package top.fangw.admin.controller;

import cn.hutool.core.bean.BeanUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.fangw.admin.pojo.entity.SysUser;
import top.fangw.admin.service.ISysUserService;
import top.fangw.common.api.dto.AddUserDto;
import top.fangw.common.api.vo.InitAdminUserVo;
import top.fangw.common.api.vo.UserVo;
import top.fangw.common.core.result.Result;
import top.fangw.common.mybatis.controller.BaseController;

/**
 * <p>
 * 用途：存储用户信息 前端控制器
 * </p>
 *
 * @author fangw
 * @since 2024-02-21
 */
@Tag(name = "用户信息管理")
@RestController
@RequestMapping("/sys-user")
@RequiredArgsConstructor
public class SysUserController extends BaseController<SysUser,ISysUserService> {
    private final ISysUserService sysUserService;


    @Operation(summary = "添加用户信息")
    @PostMapping("/add11")
    public Result<?> add(@RequestBody AddUserDto addUserDto) {
        SysUser sysUser = BeanUtil.copyProperties(addUserDto, SysUser.class);
        sysUser.setCreatedBy("1").setCreatedByName("2");
        sysUser.setUpdatedBy("2").setUpdatedByName("2");
        sysUserService.add(sysUser);
        return Result.success();
    }

    @Operation(summary = "根据用户名和租户id获取用户信息")
    @GetMapping("/selectByUsernameAndTenantId")
    public Result<UserVo> selectByUsernameAndTenantId(@RequestParam("username") String username, @RequestParam("tenantId") String tenantId) {
        UserVo userVo = sysUserService.selectByUsernameAndTenantId(username, tenantId);
        return Result.success(userVo);
    }

    @Operation(summary = "初始化租户管理员")
    @PostMapping("/initTenantAdminUser")
    public Result<InitAdminUserVo> initTenantAdminUser(@RequestBody InitAdminUserVo initAdminUserVo) {

        return Result.success(sysUserService.initTenantAdminUser(initAdminUserVo));
    }



}
